Even if GridView.DataKeyNames is set, Gridview.DataKeys[] is still empty

Posted by JustTryingToLearn on Stack Overflow See other posts from Stack Overflow or by JustTryingToLearn
Published on 2009-03-10T23:24:52Z Indexed on 2010/04/17 6:03 UTC
Read the original article Hit count: 744

Filed under:
|

hi

GridView.DataKeynames stores the names of the primary key fields for the items displayed in a GridView control.

1) Even though I’ve set DataKeyNames, GridView still doesn’t store record’s primary key value(s) in DataKey object:


protected void SqlDataSource1_Selected(object sender, 
          SqlDataSourceStatusEventArgs e)
{
      Label2.Text = GridView2.DataKeys[0].Value.ToString();//exception
}

Why not?

2) I assume when DataKeyNames is set, DataKey object stores both original and new values of a primary key ( assuming we issued an update command ) and when the update is finished, DataKey object discards the original value(s)?

Thank you

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about .NET